from collections import Counter
from collections import defaultdict
from collections import deque

from operator import index


class Solution:
    def numFriendRequests(self, ages: list[int]) -> int:#
        n = len(ages)
        if n <= 1:
            return 0
        ages.sort()
        ans = 0
        for back in range(n - 1, -1, -1):
            head = 0
            while head < back:
                if ages[back] / 2 + 7 >= ages[head]:
                    head += 1
                    continue
                if ages[head] > ages[back]:
                    head += 1
                    continue
                # 检查特殊条件：ages[head] > 100 and ages[back] < 100
                if ages[head] > 100 and ages[back] < 100:
                    head += 1
                    continue
                # 满足所有条件，可以发送好友请求
                ans += 1
                head += 1
        return ans
    def uncommonFromSentences(self, s1: str, s2: str) -> list[str]:#884
        count_s1 = Counter(s1.split())
        count_s2 = Counter(s2.split())
        result = []
        for key in count_s1.keys():
            if count_s1[key] == 1 and key not in count_s2:
                result.append(key)
        for key in count_s2.keys():
            if count_s2[key] == 1 and key not in count_s1:
                result.append(key)
        return result
    def latestTimeCatchTheBus(self, buses: list[int], passengers: list[int], capacity: int) -> int:
        buses.sort()
        passengers.sort()
        #排序后方便对比时间
        print(passengers)
        print(buses)
        last_time = 0
        for bus in buses:
            rest = capacity
            while rest > 0 and passengers:
                if passengers[0] < bus:
                    if last_time+1 < passengers[0]and last_time != passengers[0]+1 :
                        last_time = passengers[0]-1
                    if passengers[0]+1 !=passengers[1] and rest >1:
                        last_time = passengers[0]+1
                    del passengers[0]
                    rest -= 1
                elif passengers[0] == bus:
                    del passengers[0]
                    rest -= 1
                else:
                    if rest > 0 :
                        last_time = bus
                    break
        return last_time
    def longestContinuousSubstring(self, s: str) -> int:
        temp = [s[0]]
        n = len(s)
        ans = 1
        for i in range(1,n):
            if ord(s[i-1]) +1 ==   ord(s[i]):
                temp.append(s[i])
                if ans < len(temp):
                    ans = len(temp)
            else:
                temp =[s[i]]
        return ans
    def countSpecialNumbers(self, n: int) -> int:
        temp = []*10
        while n > 0:
            rest = n % 10
            n = n//10
            temp.insert(0,rest)
        for i in range(0,len(temp)):
            for j in range(0,len(temp)):
                pass
        return temp
    def longestNiceSubarray(self, nums: list[int]) -> int:
        son = [nums[0]]
        n = len(nums)
        ans = 1
        for i in range(1,n):
            is_ok =False
            cur = len(son)-1
            while son[cur] & nums[i] == 0:
                if cur == 0:
                    is_ok = True
                    break
                cur -= 1
            son.append(nums[i])
            if not is_ok:
                son = son[cur+1:]
            else:
                ans = max(ans,len(son))
        return ans
    def edgeScore(self, edges: list[int]) -> int:
        dict = defaultdict(int)
        max_value = 0
        for index, edge in enumerate(edges):
            dict[edge] += index
            if dict[edge] > max_value:
                max_value = dict[edge]
        max_keys =([key for key,value in dict.items() if value == max_value ])
        if len(max_keys) > 1:
            return min(max_keys)
        return max_keys[0]
    def findJudge(self, n: int, trust: list[list[int]]) -> int:
        believed = [0]*n
        for i in range(len(trust)):
            believed[trust[i][1]-1] += 1
        if max(believed) == n-1 :
            return believed.index(max(believed))+1
        return -1
    def maxScoreSightseeingPair(self, values: list[int]) -> int:

        max_left = values[0] + 0
        ans = 0
        for i in range(1,len(values)):
            if ans < max_left +values[i] - i:
                ans  = max_left +values[i] - i
            max_left = max(max_left,values[i] + i)
        return ans
    def deckRevealedIncreasing(self, deck: list[int]) -> list[int]:
        n = len(deck)
        index = deque(range(n))
        ans = [None]*n
        for x in sorted(deck):
            ans[index.popleft()] = x
            if index :
                index.append(index.popleft())

        return ans
    def findOcurrences(self, text: str, first: str, second: str) -> list[str]:
        words = text.split(" ")
        ans = []
        for index_word in range(len(words)-2):
            if first  == words[index_word] and second == words[index_word +1]:
                ans.append(words[index_word+2])
        return ans
    def maximumSubsequenceCount(self, text: str, pattern: str) -> int:
        n = len(text)
        right_p0 = 0
        ans = 0#考虑0
        p1 = 0
        for i in range(n):
            if text[i] == pattern[1]:
                ans += right_p0
                p1 += 1
            if text[i] == pattern[0]:
                right_p0 += 1
        ans += max(p1,right_p0)
        return ans
    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:
        ans = 0
        max_cost1 = total//cost1
        while max_cost1 >= 0:
            ans += (total - max_cost1*cost1)//cost2 +1
            max_cost1 -= 1
        return ans
    def distinctNames(self, ideas: list[str]) -> int:
        first_a = ''
        first_b = ''
        n = len(ideas)
        ans = 0
        for index_a in range(n):
            first_a = ideas[index_a][0]
            for index_b in range(index_a+1,n):
                first_b = ideas[index_b][0]
                if first_a == first_b  : continue
                if first_a + ideas[index_b][1:] in ideas or  first_b + ideas[index_a][1:] in ideas:
                    continue
                else:
                    ans += 2
        return ans
















if __name__ == '__main__':
    solution = Solution()
    print(solution.distinctNames(["lack","back"]))